/*
 * Person.java
 */

package nxtgeninventorysystem.Data;

import java.util.ArrayList;

/**
 * The Person class is meant to hold data from the Person entity so that it
 * can be easily passed as a parameter.
 * @author Seraph Softworks
 */
public class Person extends Data {

    private int id;
    private String name;
    private String team;
    private String contact_no;

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        if(name == null) {
            this.name = "";
            return;
        }
        this.name = name.replace("\\'","\'").replace("\\\"","\"");
    }

    /**
     * @return the team
     */
    public String getTeam() {
        return team;
    }

    /**
     * @param team the team to set
     */
    public void setTeam(String team) {
        if(team == null) {
            this.team = "";
            return;
        }
        this.team = team.replace("\\'","\'").replace("\\\"","\"");
    }

    /**
     * @return the contact_no
     */
    public String getContactNo() {
        return contact_no;
    }

    /**
     * @param contact_no the contact_no to set
     */
    public void setContactNo(String contact_no) {
        if(contact_no == null) {
            this.contact_no = "";
            return;
        }
        this.contact_no = contact_no.replace("\\'","\'").replace("\\\"","\"");
    }

    @Override
    public void reset() {

    }

    public ArrayList <String> getPersonSearchParametersQueryStrings(PersonSearchOptions options) {
        ArrayList<String> conditions = new ArrayList<String>();
        if (options.considerContactNo()) {
            conditions.add("contact_no like '%" + getContactNo().replace("\'","\\'").replace("\"", "\\\"") + "%'");
        }
        if (options.considerId()) {
            conditions.add("id = '" + getId() + "'");
        }
        if (options.considerName()) {
            conditions.add("name like '%" + getName().replace("\'","\\'").replace("\"", "\\\"") + "%'");
        }
        if (options.considerTeam()) {
            conditions.add("team = '" + getTeam().replace("\'","\\'").replace("\"", "\\\"") + "'");
        }
        return conditions;
    }

}
